package com.mine.modules.sys.controller;

import com.mine.common.annotation.AutoLog;
import com.mine.common.constant.CommonConstant;
import com.mine.common.domain.vo.Result;
import com.mine.modules.sys.domain.dto.LoginDto;
import com.mine.modules.sys.service.ILoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@RestController
@RequestMapping("/sys")
@Api(tags = "用户登录")
@Slf4j
@RequiredArgsConstructor
public class LoginController {

    private final ILoginService loginService;

    @ApiOperation("登录接口")
    @AutoLog(value = "用户登录")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public Result<Object> login(LoginDto loginDto) throws Exception {
        return loginService.login(loginDto);
    }

    @ApiOperation("退出登录")
    @AutoLog(value = "退出登录", logType = CommonConstant.LOG_TYPE_2)
    @RequestMapping(value = "/logout", method = RequestMethod.GET)
    public Result<Object> logout(HttpServletRequest request, HttpServletResponse response) {
        return loginService.logout(request, response);
    }

    @ApiOperation("获取图形验证码")
    @RequestMapping(value = "/randomImage", method = RequestMethod.GET)
    public Result<String> randomImage(HttpServletResponse response, @PathVariable("key") String key) {
        return loginService.randomImage(response, key);
    }

}